/**
 * 
 * @param {Object} options - 上传选项
 * @param {string} options.url - 服务器端上传接口地址
 * @param {string} options.filePath - 要上传的本地文件路径
 * @param {string} [options.name='file'] - 上传文件的字段名
 * @param {Object} [options.formData={}] - 附加到请求体中的额外数据
 * @param {Function} [options.onProgressUpdate] - 上传进度回调
 * @returns {Promise<Object>} - 上传结果对象
 */
export uploadFile(options) {
	return new Promise((resolve, reject) => {
		// 合并默认参数与传入参数
		const mergedOptions = Object.assign({
				name: 'file',
				formData: {},
			},
			options
		);

		// 调用uni.uploadFile
		uni.uploadFile({
			url: mergedOptions.url,
			filePath: mergedOptions.filePath,
			name: mergedOptions.name,
			formData: mergedOptions.formData,
			header: {
				'Content-Type': 'multipart/form-data',
			},
			success: (res) => {
				const {
					statusCode,
					data
				} = res;
				if (statusCode === 200) {
					resolve(JSON.parse(data));
				} else {
					reject(new Error(`Upload failed with status code ${statusCode}`));
				}
			},
			fail: (err) => {
				reject(err);
			},
			complete: () => {
				// 可在此处清除临时文件等清理工作
			},
			onProgressUpdate: mergedOptions.onProgressUpdate,
		});
	});
}